package com.ruoyi.crawler.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.Utils.H5Util;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.crawler.mapper.WebRecordMapper;
import com.ruoyi.crawler.domain.WebRecord;
import com.ruoyi.crawler.service.IWebRecordService;

/**
 * 爬虫记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-29
 */
@Service
public class WebRecordServiceImpl implements IWebRecordService 
{
    @Autowired
    private WebRecordMapper webRecordMapper;

    /**
     * 查询爬虫记录
     * 
     * @param id 爬虫记录主键
     * @return 爬虫记录
     */
    @Override
    public WebRecord selectWebRecordById(Long id)
    {
        return webRecordMapper.selectWebRecordById(id);
    }

    /**
     * 查询爬虫记录列表
     * 
     * @param webRecord 爬虫记录
     * @return 爬虫记录
     */
    @Override
    public List<WebRecord> selectWebRecordList(WebRecord webRecord)
    {
        return webRecordMapper.selectWebRecordList(webRecord);
    }

    /**
     * 新增爬虫记录
     * 
     * @param webRecord 爬虫记录
     * @return 结果
     */
    @Override
    public int insertWebRecord(WebRecord webRecord)
    {
        webRecord.setCreateTime(DateUtils.getNowDate());
        return webRecordMapper.insertWebRecord(webRecord);
    }

    /**
     * 修改爬虫记录
     * 
     * @param webRecord 爬虫记录
     * @return 结果
     */
    @Override
    public int updateWebRecord(WebRecord webRecord)
    {
        return webRecordMapper.updateWebRecord(webRecord);
    }

    /**
     * 批量删除爬虫记录
     * 
     * @param ids 需要删除的爬虫记录主键
     * @return 结果
     */
    @Override
    public int deleteWebRecordByIds(Long[] ids)
    {
        return webRecordMapper.deleteWebRecordByIds(ids);
    }

    /**
     * 删除爬虫记录信息
     * 
     * @param id 爬虫记录主键
     * @return 结果
     */
    @Override
    public int deleteWebRecordById(Long id)
    {
        return webRecordMapper.deleteWebRecordById(id);
    }

    @Override
    public Map<String, Object> getH5Crawler(WebRecord webRecord) {
        Map<String,Object> result = new HashMap<>();
        List<String> imgList = H5Util.getAllImg(webRecord.getHtml(),null);
        result.put("imgs",imgList);
        return result;
    }
}
